package fr.alesia.deepstack.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

@SuppressWarnings("serial")
public class MenuServlet extends HttpServlet {

	@Override
	protected void doGet(
		HttpServletRequest request,
		HttpServletResponse response
	) throws ServletException, IOException {
		
		ServletContext context = this.getServletContext();
		
		UserService service = UserServiceFactory.getUserService();
		String uri = request.getRequestURI();
		String urlLogin = service.createLoginURL(uri);
		String urlLogout = service.createLogoutURL(uri);
		
		request.setAttribute("urlLogin", urlLogin);
		request.setAttribute("urlLogout", urlLogout);
		
		RequestDispatcher dispatcher = context.getRequestDispatcher("/webapp/page/public/deepstack.jsp");
		dispatcher.forward(request, response);
	}

	@Override
	protected void doPost (
		HttpServletRequest request,
		HttpServletResponse response
	) throws ServletException, IOException {
		
		this.doGet(request, response);
	}
}
